package cn.itcast.java.serialize;

import java.io.*;

/**
 * Author itcast
 * Date 2021/10/13 6:29
 * Desc TODO
 */
public class ObjectOutputStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("data/output/student.txt"));
        Student zhangsan = new Student("zhangsan", 30,10);
        oos.writeObject(zhangsan);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("data/output/student.txt"));
        Object obj = ois.readObject();
        if( obj instanceof Student) {
            Student object = (Student) obj;
            System.out.println(object);
        }
        ois.close();
    }
}
